<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------
namespace Admin\Controller;

/**
 * 模型数据管理控制器
 * @author 麦当苗儿 <zuojiazi@vip.qq.com>
 */
class GasController extends ThinkController {

	private $station_mid = 18;
	private $oiltype_mid = 20;
	private $oilgun_mid = 21;

    public function gunadd($osid = 0){

        $this->assign('active_menu','gas/stations');
        parent::add($this->oilgun_mid);
    }

    public function gunedit($model = null, $id = 0){

        $this->assign('active_menu','gas/stations');
        parent::edit($this->oilgun_mid,$id);
    }

    public function gunlists($osid = 0){

        $osid = intval($osid);
        $ot_list = M('scyq_oil_type')->getField('id,oil_name');

        $model = M('smjy_oil_gun');
        $list = $this->plists($model,['oil_station_id'=>$osid]);

        $this->assign('_list',$list);
        $this->assign('ot_list',[''=>'请选择']+$ot_list);
        $this->assign('osid',$osid);
        $this->meta_title = '油枪管理';
        $this->display();
    }
    /**
     * 显示指定模型列表数据
     * @author 麦当苗儿 <zuojiazi@vip.qq.com>
     * @param int $p
     */
    public function stations($p = 0){
        $this->assign('active_menu','gas/stations');
        $this->lists('smjy_oil_station',$p);
    }

    public function addStation(){
        $this->assign('active_menu','gas/stations');
        $_POST['create_time'] = time_format();
        parent::add($this->station_mid);
    }

    public function oiltype($p = 0){
        $this->assign('active_menu','gas/oiltype');
        $this->lists('scyq_oil_type',$p);
    }

    public function add($model = null){
        if($model == $this->oiltype_mid){
            $this->assign('active_menu','gas/oiltype');
            parent::add($this->oiltype_mid,'gas/oiltype');
        }elseif($model == $this->oilgun_mid){

            $this->assign('active_menu','gas/stations');
            parent::add($this->oilgun_mid,'gas/gunlists/osid/'.intval(I('oil_station_id')));
        }
    }

    public function edit($model = null, $id = 0){
        if($model == $this->oiltype_mid){
            $this->assign('active_menu','gas/oiltype');
            parent::edit($model,$id,'gas/oiltype');
        }elseif($model == $this->oilgun_mid){
            $this->assign('active_menu','gas/stations');
            parent::edit($this->oilgun_mid,$id,'gas/gunlists/osid/'.intval(I('oil_station_id')));
        }else{
            parent::edit($model,$id);
        }
    }
}